<?php

namespace  App\middlewares;

use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

/**
 * 
 */
class Params
{
    private $params;
    public function __construct($params = [])
    {
        $this->params = $params;
    }

    public function __invoke(ServerRequestInterface $request,ResponseInterface $response,callable $next)
    {
        foreach ($this->params as $key => $value) {
            if(!isset($request->getParsedBody()[$value])){
                return $response->withJson([
                    'code' => 403,
                    'error' => '参数错误!'
                    ],403);
            }
        }
        $response =$next($request,$response);
        return $response;

    }
}
